home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_04
/
1004091b
< prev
next >
Wrap
Text File
|
1992-02-08
|
767b
|
45 lines
void push(stack *st, void *pvalue)
{
if (st->stack_ptr == st->max_stack)
printf("Stack %s is full\n", st->stack_name);
else
switch (st->type) {
case INT:
((int *)st->pstack)[st->stack_ptr++] = *(int *)pvalue;
break;
case LONG:
((long *)st->pstack)[st->stack_ptr++] = *(long *)pvalue;
break;
case DOUBLE:
((double *)st->pstack)[st->stack_ptr++] = *(double *)pvalue;
break;
}
}
void *pop(stack *st)
{
if (st->stack_ptr == 0) {
printf("Stack %s is empty\n", st->stack_name);
return 0;
}
switch (st->type) {
case INT:
return &((int *)st->pstack)[--st->stack_ptr];
break;
case LONG:
return &((long *)st->pstack)[--st->stack_ptr];
break;
case DOUBLE:
return &((long *)st->pstack)[--st->stack_ptr];
break;
}
}